package com.atlin.license;

import oshi.SystemInfo;
import oshi.hardware.*;

import java.util.List;

public class SystemIdDemo {
    public static void main(String[] args) {
        SystemInfo si = new SystemInfo();
        HardwareAbstractionLayer hal = si.getHardware();

        // 1. 主板序列号 (相对可靠)
        ComputerSystem computerSystem = hal.getComputerSystem();
        String motherboardSerial = computerSystem.getBaseboard().getSerialNumber();
        String processorID = hal.getProcessor().getProcessorIdentifier().getProcessorID();
        System.out.println("Motherboard Serial: " + motherboardSerial);
        System.out.println("processorID Serial: " + processorID);

        // 2. 硬盘序列号 (选择系统盘)
        List<HWDiskStore> disks = hal.getDiskStores();
        String diskSerial = "";
        if (!disks.isEmpty()) {
            diskSerial = disks.get(0).getSerial(); // 第一个磁盘的序列号
            System.out.println("Disk Serial: " + diskSerial);
        }

        // 3. MAC地址 (选择第一个非虚拟的网卡)
        List<NetworkIF> networks = hal.getNetworkIFs();
        for (NetworkIF net : networks) {
            String mac = net.getMacaddr();
            if (!mac.isEmpty() && !mac.equals("00:00:00:00:00:00")) {
                System.out.println("MAC Address: " + mac);
                break;
            }
        }

        // 组合生成一个系统ID (示例)
        String systemIdentifier = motherboardSerial + "-" + diskSerial;
        // 注意：可以对组合后的字符串进行哈希（如SHA-256）以增强隐私保护。
        System.out.println("System Identifier: " + systemIdentifier);
    }
}